package com.guigu.www.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.guigu.www.pojo.Cell;
import com.guigu.www.pojo.Gather;
import com.guigu.www.pojo.GatherDetails;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.service.CellService;
import com.guigu.www.service.GatherDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class GatherDetailsConntroller {
    //获取service明细表
    @Autowired
    GatherDetailsService gatherDetailsService;

    //入库单元表
    @Autowired
    CellService cellService;

    //根据产入库产品查询产品
    @RequestMapping("/queryGatherDetailsByproductId.action")
    public GatherDetails queryGatherDetailsByproductId(String productId,int ids){
        //获取方法
       return gatherDetailsService.queryGatherDetailsByproductId(productId,ids);
    }

    //入库调度单提交  修改明细表状态为GATHER_TAG K002-2 修改库存单元数量
    @RequestMapping("updateGatherDetailsCell.action")
    public Map updateGatherDetailsCell(@RequestBody  GatherDetails gatherDetails){
        //创建map
        Map map=new HashMap();
        System.out.println(gatherDetails);
        //修改明细表 确定数量设置
        boolean f=gatherDetailsService.updateGatherDetailsByproductId(gatherDetails.getGatheredAmount(),gatherDetails.getProductId());
        /*//修改库存单元表
        boolean f1=cellService.updateCellByproductId(cell);*/
        //判断
        map.put("msg","调度失败");
        if(f){
            map.put("msg","调度成功");
        }
        return map;
    }

    //根据产品编号 产品父id查询
    @RequestMapping("/querygatherDetailsBycpidByid.action")
    public GatherDetails querygatherDetailsBycpidByid(int id,String productId){
        return  gatherDetailsService.querygatherDetailsBycpidByid(id,productId);
    }

    //库存入库明细
    @RequestMapping("/queryBydynamicinventiryall.action")
    public PageVo<GatherDetails> queryBydynamicinventiryall(@RequestParam(value = "pageno",defaultValue = "1") int pageno,@RequestParam(value = "pagesize",defaultValue = "5") int pagesize, String productId){
        //调用方法
        //创建pagevo
        PageVo<GatherDetails> pageVo=new PageVo<GatherDetails>();
        //调用方法
        PageInfo<GatherDetails> page=gatherDetailsService.queryBydynamicinventiryall(pageno,pagesize,productId);
        pageVo.setRows(page.getList());
        pageVo.setTotal(page.getTotal());
        return pageVo;
    }
}
